﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.DialogUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import Transactions.*;
    import Classes.util.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.event.*;
    import org.aswing.border.*;
    import Display.aswingui.*;
    import Modules.stats.types.*;

    public class DailyDripDialogView extends GenericDialogView {

        public static const DIALOG_TEXT_WIDTH:int = 350;
        public static const CHECK_PANE_SIZE:int = 40;
        public static const OVERLAP_AMOUNT:int = 10;

        protected var m_itemCheck:int = 0;
        protected var m_textAreaInnerPane:JPanel;
        protected var m_textAP:Component;
        protected var m_overlapPane:JPanel;
        protected var m_bottomPane:JPanel;
        protected var m_subtitleString:String = "";
        protected var m_checkWidth:int = 0;
        protected var m_bgSel:Array;
        protected var m_bg:Array;
        protected var m_cellBG:DisplayObject = null;
        protected var m_ctrCnt:Array;
        protected var m_check:Array;
        protected var m_hover:int = -1;

        public function DailyDripDialogView(_arg1:Dictionary, _arg2:String="", _arg3:String="", _arg4:String="", _arg5:Function=null, _arg6:Function=null){
            this.m_bgSel = [];
            this.m_bg = [];
            this.m_ctrCnt = [];
            this.m_check = [];
            this.m_subtitleString = _arg4;
            this.m_itemCheck = (Math.random() * 3);
            if (this.m_itemCheck > 2){
                this.m_itemCheck = 2;
            };
            super(_arg1, _arg2, _arg3, TYPE_OK, _arg5, "", 0, "", _arg6);
        }
        override protected function createTitlePanel():JPanel{
            var _local1:JPanel = super.createTitlePanel();
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            m_titleFontSize = TextFieldUtil.getLocaleFontSize(30, 20, null);
            var _local3:AssetPane = ASwingHelper.makeMultilineText(this.m_subtitleString, DIALOG_TEXT_WIDTH, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.CENTER, m_titleFontSize, EmbeddedArt.blueTextColor);
            _local2.append(_local3);
            ASwingHelper.setEasyBorder(_local2, 0, 10, 0, 10);
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            _local4.appendAll(_local1, _local2);
            return (_local4);
        }
        override protected function createInteriorHolder():JPanel{
            var _local1:JPanel = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, -10, AsWingConstants.CENTER));
            var _local2:JPanel = createHeaderPanel();
            ASwingHelper.prepare(_local2);
            textArea = this.createTextArea();
            ASwingHelper.prepare(textArea);
            _local1.setBorder(new EmptyBorder(null, new Insets(0, 0, 0, 0)));
            _local1.append(_local2);
            _local1.append(ASwingHelper.verticalStrut(10));
            _local1.append(textArea);
            _local1.append(ASwingHelper.verticalStrut((2 * BUTTON_MARGIN)));
            var _local3:JPanel = createButtonPanel();
            _local1.append(_local3);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        override protected function createTextArea():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 10);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER, 10);
            ASwingHelper.setEasyBorder(_local2, 10);
            var _local3:JPanel = this.createCenterArea();
            _local2.append(_local3);
            this.m_textAP = this.createText(m_message, DIALOG_TEXT_WIDTH, EmbeddedArt.blueTextColor);
            this.m_textAreaInnerPane = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            this.m_textAreaInnerPane.append(this.m_textAP);
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local4.append(this.m_textAreaInnerPane);
            ASwingHelper.prepare(_local4);
            _local2.append(_local4);
            ASwingHelper.prepare(_local2);
            _local1.append(_local2);
            return (_local1);
        }
        protected function createText(_arg1:String, _arg2:Number, _arg3:uint):JPanel{
            var _local4:Component = ASwingHelper.makeMultilineText(_arg1, _arg2, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.CENTER, 18, _arg3);
            var _local5:JPanel = ASwingHelper.makeSoftBoxJPanelVertical();
            _local5.append(_local4);
            return (_local5);
        }
        protected function createCenterArea():JPanel{
            var _local1:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT, 10);
            var _local2 = 20;
            _local1.append(ASwingHelper.horizontalStrut((_local2 + (OVERLAP_AMOUNT / 2))));
            var _local3:int;
            while (_local3 < 3) {
                this.m_overlapPane = this.createCell(_local3);
                _local1.append(this.m_overlapPane);
                _local3++;
            };
            _local1.append(ASwingHelper.horizontalStrut(_local2));
            return (_local1);
        }
        protected function handleMouseOver(_arg1:MouseEvent, _arg2:int):void{
            if ((((_arg2 >= 0)) && ((_arg2 < this.m_check.length)))){
                if (((!((_arg2 == this.m_itemCheck))) && (!((_arg2 == this.m_hover))))){
                    this.m_hover = _arg2;
                    this.m_ctrCnt[this.m_hover].setBackgroundDecorator(this.m_bgSel[this.m_hover]);
                };
            };
        }
        protected function handleMouseOut(_arg1:MouseEvent, _arg2:int):void{
            if ((((((this.m_hover >= 0)) && ((this.m_hover < this.m_check.length)))) && (!((this.m_hover == this.m_itemCheck))))){
                this.m_ctrCnt[this.m_hover].setBackgroundDecorator(this.m_bg[this.m_hover]);
            };
            this.m_hover = -1;
        }
        protected function handleMouseDown(_arg1:MouseEvent, _arg2:int):void{
            if (_arg2 == this.m_itemCheck){
                return;
            };
            if ((((this.m_itemCheck >= 0)) && ((this.m_itemCheck < this.m_check.length)))){
                this.m_check[this.m_itemCheck].visible = false;
                this.m_ctrCnt[this.m_itemCheck].setBackgroundDecorator(this.m_bg[this.m_itemCheck]);
            };
            if ((((_arg2 >= 0)) && ((_arg2 < this.m_check.length)))){
                this.m_itemCheck = _arg2;
                this.m_check[this.m_itemCheck].visible = true;
                this.m_ctrCnt[this.m_itemCheck].setBackgroundDecorator(this.m_bgSel[this.m_itemCheck]);
            };
        }
        protected function createCell(_arg1:int):JPanel{
            var ndx:* = _arg1;
            var checkPane:* = this.makeCheckPane(ndx);
            var centeringContainer:* = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var cellBG1:* = (new (m_assetDict["cell_bg"])() as DisplayObject);
            this.m_bg[ndx] = new MarginBackground(cellBG1);
            this.m_cellBG = (new (m_assetDict["cell_bg_ready"])() as DisplayObject);
            this.m_bgSel[ndx] = new MarginBackground(this.m_cellBG);
            var bgDec:* = this.m_bg[ndx];
            centeringContainer.setBackgroundDecorator(bgDec);
            centeringContainer.setPreferredSize(new IntDimension(this.m_cellBG.width, this.m_cellBG.height));
            centeringContainer.setMinimumSize(new IntDimension(this.m_cellBG.width, this.m_cellBG.height));
            centeringContainer.setMaximumSize(new IntDimension(this.m_cellBG.width, this.m_cellBG.height));
            this.m_ctrCnt[ndx] = centeringContainer;
            var overlap:* = 0;
            if (this.m_checkWidth){
                overlap = (OVERLAP_AMOUNT - this.m_checkWidth);
            };
            var overlapPane:* = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.BOTTOM, overlap);
            var itemIconPane:* = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var itemIcon:* = (new (m_assetDict["itemIcon"][ndx])() as DisplayObject);
            var iconAlignPane:* = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var iconPane:* = new AssetPane(itemIcon);
            var widthToCenter:* = ((this.m_cellBG.width - itemIcon.width) / 2);
            iconAlignPane.append(ASwingHelper.horizontalStrut(widthToCenter));
            iconAlignPane.append(iconPane);
            itemIconPane.append(iconAlignPane);
            centeringContainer.append(itemIconPane);
            overlapPane.append(centeringContainer);
            this.m_bottomPane = new JPanel(new BorderLayout());
            this.m_bottomPane.append(checkPane, BorderLayout.SOUTH);
            overlapPane.append(this.m_bottomPane);
            var text:* = this.createText(m_assetDict["itemLabel"][ndx], this.m_cellBG.width, EmbeddedArt.brownTextColor);
            overlapPane.addEventListener(MouseEvent.MOUSE_OVER, function (_arg1:MouseEvent):void{
                handleMouseOver(_arg1, ndx);
            }, false, 0, false);
            overlapPane.addEventListener(MouseEvent.MOUSE_DOWN, function (_arg1:MouseEvent):void{
                handleMouseDown(_arg1, ndx);
            }, false, 0, false);
            overlapPane.addEventListener(MouseEvent.MOUSE_OUT, function (_arg1:MouseEvent):void{
                handleMouseOut(_arg1, ndx);
            }, false, 0, false);
            overlapPane.buttonMode = true;
            var container:* = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            container.append(overlapPane);
            text.setMinimumHeight(40);
            text.setPreferredHeight(40);
            container.append(text);
            ASwingHelper.prepare(container);
            if (ndx == this.m_itemCheck){
                this.m_check[ndx].visible = true;
                this.m_ctrCnt[ndx].setBackgroundDecorator(this.m_bgSel[ndx]);
            };
            return (container);
        }
        protected function makeCheckPane(_arg1:int):JPanel{
            var _local4:DisplayObject;
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.BOTTOM);
            var _local5:uint = 0xFFFFFF;
            var _local6:Class = (assetDict["check_mark"] as Class);
            _local4 = (new (_local6)() as DisplayObject);
            this.m_check[_arg1] = _local4;
            this.m_checkWidth = _local4.width;
            _local2.setBackgroundDecorator(new AssetBackground(_local4));
            _local2.setPreferredHeight(_local4.height);
            _local2.setMinimumHeight(_local4.height);
            _local2.setMaximumHeight(_local4.height);
            _local2.setPreferredWidth(_local4.width);
            _local2.setMinimumWidth(_local4.width);
            _local2.setMaximumWidth(_local4.width);
            _local2.append(_local3);
            _local4.visible = false;
            ASwingHelper.prepare(_local2);
            return (_local2);
        }
        override protected function onAccept(_arg1:AWEvent):void{
            var _local2:String = assetDict["rewardType"][this.m_itemCheck];
            StatsManager.sample(100, StatsCounterType.DAILY_BONUS, "email", "email_reward_signup", _local2);
            GameTransactionManager.addTransaction(new TQueueDailyDrip(_local2), true);
            if (m_closeCallback != null){
                removeEventListener(GenericPopupEvent.SELECTED, m_closeCallback);
            };
            closeMe();
            var _local3:String = ZLoc.t("Dialogs", "DailyDripConfirmation");
            var _local4:GenericDialog = new GenericDialog(_local3, "", TYPE_OK);
            UI.displayPopup(_local4, true, "DripConfirm", true);
        }
        override protected function onCancel(_arg1):void{
            super.onCancel(_arg1);
            StatsManager.sample(100, StatsCounterType.DAILY_BONUS, "email", "email_reward_decline");
            GameTransactionManager.addTransaction(new TQueueDailyDrip("decline"), false);
        }

    }
}//package Display.DialogUI 
